package com.activenetwork.smlite.testcase.events.createEvents.basics;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.schema.model.event.EventBasicType;
import com.activenetwork.smlite.page.event.EventDetailView.EventBasicSubview;
import com.activenetwork.smlite.snippet.EventsSnippet;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.RandomString;
import com.activenetwork.util.verification.gson.FailurePoint;

public class Basics015 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(Basics015.class);
	private EventBasicType.Tag tag;
	@BeforeClass(alwaysRun = true)
	public void dataSetup(){
		tag = new EventBasicType.Tag();
		tag.setTagName("autotest-tag-"+RandomString.generateRandomString(5));
		tag.setTagDesc("autotest-tag-description");
		tag.setPrivate(false);
	}
	
	@Test
	public void Verify_add_new_Tag_works_correctly(){
		loginBusiness.login();
		EventBasicSubview eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		// test cancel after adding tag
		eventBasicSubview = eventBasicSubview.setTag(tag);
		eventBasicSubview = eventBasicSubview.cancelTag();
		
		// test save after adding same tag
		eventBasicSubview = eventBasicSubview.setTag(tag);
		eventBasicSubview = eventBasicSubview.saveTag();
		
		// test the added tag can be found from suggest list
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		try{
			eventBasicSubview.selectEventTagAJAX(tag);
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics015.class.getName(), 
					"Verify add new tag and can be found from suggest list", 
					"New tag added but can not be found from the suggest list"));
		}
		
		loginBusiness.logout();
	}
}
